<template>
  <div>
    <button @click="handleClick">{{isCountDown()}}</button>
  </div>
</template>

<script>
export default{
  name: 'CountDown',
  components: {},
  props:{
    time:{
      type:[Number,String]
    }
  },
  data(){
    return {
      strat:"",
      num : "开始倒计时"

    }
  },
  methods:{
    isCountDown(){
      return this.num?this.num:this.time;
    },
    handleClick(){
      alert("开始倒计时")
      this.num = this.time
      this.id = setInterval(()=>{
       this.num--;
       if(this.num == 0 ){
        clearInterval(this.id);
        this.num = "开始倒计时";
       }
      },1000)
    }
  }
};
</script>

<style scoped lang='scss'>

</style>